<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Macro BOOST_CONTRACT_OLD_PTR_IF_COPYABLE</title>
<link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="index.html" title="Chapter 1. Boost.Contract 1.0.0">
<link rel="up" href="reference.html#header.boost.contract_macro_hpp" title="Header &lt;boost/contract_macro.hpp&gt;">
<link rel="prev" href="BOOST_CONTRACT_OLD_PTR.html" title="Macro BOOST_CONTRACT_OLD_PTR">
<link rel="next" href="BOOST_CONTRACT_INVARIANT.html" title="Macro BOOST_CONTRACT_INVARIANT">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td>
<td align="center"><a href="../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="BOOST_CONTRACT_OLD_PTR.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="reference.html#header.boost.contract_macro_hpp"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="BOOST_CONTRACT_INVARIANT.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="refentry">
<a name="BOOST_CONTRACT_OL_idm37198"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2><span class="refentrytitle">Macro BOOST_CONTRACT_OLD_PTR_IF_COPYABLE</span></h2>
<p>BOOST_CONTRACT_OLD_PTR_IF_COPYABLE — Program old values that can be completely disabled at compile-time for old value types that are not required to be copyable. </p>
</div>
<h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2>
<div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: &lt;<a class="link" href="reference.html#header.boost.contract_macro_hpp" title="Header &lt;boost/contract_macro.hpp&gt;">boost/contract_macro.hpp</a>&gt;

</span>BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(...)</pre></div>
<div class="refsect1">
<a name="idm45004"></a><h2>Description</h2>
<p>This is used to program old value copies for types that might or might not be copyable:</p>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="comment">// Type `T` might or not be copyable.</span>
<span class="keyword">class</span> <span class="identifier">u</span> <span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
    <span class="keyword">void</span> <span class="identifier">f</span><span class="special">(</span><span class="special">...</span><span class="special">)</span> <span class="special">{</span>
        <span class="identifier">BOOST_CONTRACT_OLD_PTR_IF_COPYABLE</span><span class="special">(</span><span class="identifier">old_type_a</span><span class="special">)</span><span class="special">(</span><span class="identifier">old_var_a</span><span class="special">)</span><span class="special">;</span>
        <span class="identifier">BOOST_CONTRACT_OLD_PTR_IF_COPYABLE</span><span class="special">(</span><span class="identifier">old_type_b</span><span class="special">)</span><span class="special">(</span><span class="identifier">old_var_b</span><span class="special">,</span>
                <span class="identifier">old_expr_b</span><span class="special">)</span><span class="special">;</span>
        <span class="identifier">BOOST_CONTRACT_PUBLIC_FUNCTION</span><span class="special">(</span><span class="keyword">this</span><span class="special">)</span>
            <span class="special">...</span>
            <span class="identifier">BOOST_CONTRACT_OLD</span><span class="special">(</span><span class="special">[</span><span class="special">&amp;</span><span class="special">]</span> <span class="special">{</span>
                <span class="identifier">old_var_a</span> <span class="special">=</span> <span class="identifier">BOOST_CONTRACT_OLDOF</span><span class="special">(</span><span class="identifier">old_expr_a</span><span class="special">)</span><span class="special">;</span>
                <span class="special">...</span>
            <span class="special">}</span><span class="special">)</span>
            <span class="special">...</span> <span class="comment">// In postconditions or exception guarantees:</span>
                <span class="keyword">if</span><span class="special">(</span><span class="identifier">old_var_a</span><span class="special">)</span> <span class="special">...</span> <span class="comment">// Always null for non-copyable types.</span>
                <span class="keyword">if</span><span class="special">(</span><span class="identifier">old_var_b</span><span class="special">)</span> <span class="special">...</span> <span class="comment">// Always null for non-copyable types.</span>
            <span class="special">...</span>
        <span class="special">;</span>

        <span class="special">...</span> <span class="comment">// Function body.</span>
    <span class="special">}</span>

    <span class="keyword">virtual</span> <span class="keyword">void</span> <span class="identifier">g</span><span class="special">(</span><span class="special">...</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">contract</span><span class="special">::</span><span class="identifier">virtual_</span><span class="special">*</span> <span class="identifier">v</span> <span class="special">=</span> <span class="number">0</span><span class="special">)</span> <span class="special">{</span>
        <span class="identifier">BOOST_CONTRACT_OLD_PTR_IF_COPYABLE</span><span class="special">(</span><span class="identifier">old_type_a</span><span class="special">)</span><span class="special">(</span><span class="identifier">old_var_a</span><span class="special">)</span><span class="special">;</span>
        <span class="identifier">BOOST_CONTRACT_OLD_PTR_IF_COPYABLE</span><span class="special">(</span><span class="identifier">old_type_b</span><span class="special">)</span><span class="special">(</span><span class="identifier">v</span><span class="special">,</span> <span class="identifier">old_var_b</span><span class="special">,</span>
                <span class="identifier">old_expr_b</span><span class="special">)</span><span class="special">;</span>
        <span class="identifier">BOOST_CONTRACT_PUBLIC_FUNCTION</span><span class="special">(</span><span class="identifier">v</span><span class="special">,</span> <span class="keyword">this</span><span class="special">)</span>
            <span class="special">...</span>
            <span class="identifier">BOOST_CONTRACT_OLD</span><span class="special">(</span><span class="special">[</span><span class="special">&amp;</span><span class="special">]</span> <span class="special">{</span>
                <span class="identifier">old_var_a</span> <span class="special">=</span> <span class="identifier">BOOST_CONTRACT_OLDOF</span><span class="special">(</span><span class="identifier">v</span><span class="special">,</span> <span class="identifier">old_expr_a</span><span class="special">)</span><span class="special">;</span>
                <span class="special">...</span>
            <span class="special">}</span><span class="special">)</span>
            <span class="special">...</span> <span class="comment">// In postconditions or exception guarantees:</span>
                <span class="keyword">if</span><span class="special">(</span><span class="identifier">old_var_a</span><span class="special">)</span> <span class="special">...</span> <span class="comment">// Always null for non-copyable types.</span>
                <span class="keyword">if</span><span class="special">(</span><span class="identifier">old_var_b</span><span class="special">)</span> <span class="special">...</span> <span class="comment">// Always null for non-copyable types.</span>
            <span class="special">...</span>
        <span class="special">;</span>

        <span class="special">...</span> <span class="comment">// Function body.</span>
    <span class="special">}</span>

    <span class="special">...</span>
<span class="special">}</span><span class="special">;</span>
</pre>
<p>This is an overloaded variadic macro and it can be used in the following different ways (note that no code is generated when  <code class="computeroutput"><a class="link" href="BOOST_CONTRACT_NO_OLDS.html" title="Macro BOOST_CONTRACT_NO_OLDS">BOOST_CONTRACT_NO_OLDS</a></code> is defined).</p>
<p>1. <code class="computeroutput">BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(old_type)(old_var)</code> expands to code equivalent to the following (this leaves the old value pointer null):</p>
<pre class="programlisting"><span class="preprocessor">#ifndef</span> <span class="identifier">BOOST_CONTRACT_NO_OLDS</span>
    <span class="comment">// This declaration does not need to use `v`.</span>
    <span class="identifier">boost</span><span class="special">::</span><span class="identifier">contract</span><span class="special">::</span><span class="identifier">old_ptr_if_copyable</span><span class="special">&lt;</span><span class="identifier">old_type</span><span class="special">&gt;</span> <span class="identifier">old_var</span>
<span class="preprocessor">#endif</span>
</pre>
<p>2. <code class="computeroutput">BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(old_type)(old_var, old_expr)</code> expands to code equivalent to the following (this initializes the pointer to the old value copy, but not to be used for virtual public functions and public function overrides):</p>
<pre class="programlisting"><span class="preprocessor">#ifndef</span> <span class="identifier">BOOST_CONTRACT_NO_OLDS</span>
    <span class="identifier">boost</span><span class="special">::</span><span class="identifier">contract</span><span class="special">::</span><span class="identifier">old_ptr_if_copyable</span><span class="special">&lt;</span><span class="identifier">old_type</span><span class="special">&gt;</span> <span class="identifier">old_var</span> <span class="special">=</span>
            <span class="identifier">BOOST_CONTRACT_OLDOF</span><span class="special">(</span><span class="identifier">old_expr</span><span class="special">)</span>
<span class="preprocessor">#endif</span>
</pre>
<p>3. <code class="computeroutput">BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(old_type)(v, old_var, old_expr)</code> expands to code equivalent to the following (this initializes the pointer to the old value copy for virtual public functions and public function overrides):</p>
<pre class="programlisting"><span class="preprocessor">#ifndef</span> <span class="identifier">BOOST_CONTRACT_NO_OLDS</span>
    <span class="identifier">boost</span><span class="special">::</span><span class="identifier">contract</span><span class="special">::</span><span class="identifier">old_ptr_if_copyable</span><span class="special">&lt;</span><span class="identifier">old_type</span><span class="special">&gt;</span> <span class="identifier">old_var</span> <span class="special">=</span>
            <span class="identifier">BOOST_CONTRACT_OLDOF</span><span class="special">(</span><span class="identifier">v</span><span class="special">,</span> <span class="identifier">old_expr</span><span class="special">)</span>
<span class="preprocessor">#endif</span>
</pre>
<p>Where:</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem"><p><code class="computeroutput"><span class="bold"><strong>old_type</strong></span></code> is the type of the pointed old value. If this type is not copyable (i.e., <code class="computeroutput">boost::contract::is_old_value_copyable&lt;old_type&gt;::value</code> is <code class="computeroutput">false</code>), this pointer will always be null, but this library will not generate a compile-time error when this pointer is dereferenced (see <code class="computeroutput"><a class="link" href="BOOST_CONTRACT_OLD_PTR.html" title="Macro BOOST_CONTRACT_OLD_PTR">BOOST_CONTRACT_OLD_PTR</a></code>). (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.) </p></li>
<li class="listitem"><p><code class="computeroutput"><span class="bold"><strong>v</strong></span></code> is the extra trailing parameter of type  <code class="computeroutput"><a class="link" href="boost/contract/virtual_.html" title="Class virtual_">boost::contract::virtual_</a></code><code class="computeroutput">*</code> and default value <code class="computeroutput">0</code> from the enclosing virtual public function or public function override declaring the contract. (This is not a variadic macro parameter but it should never contain commas because it is an identifier.) </p></li>
<li class="listitem"><p><code class="computeroutput"><span class="bold"><strong>old_var</strong></span></code> is the name of the old value pointer variable. (This is not a variadic macro parameter but it should never contain commas because it is an identifier.) </p></li>
<li class="listitem"><p><code class="computeroutput"><span class="bold"><strong>old_expr</strong></span></code> is the expression to be evaluated and copied in the old value pointer. (This is not a variadic macro parameter so any comma it might contain must be protected by round parenthesis and <code class="computeroutput">BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(old_type)(v, old_var, (old_expr))</code> will always work.)</p></li>
</ul></div>
<p>
</p>
<p><span class="bold"><strong>See Also:</strong></span></p>
<p> <a class="link" href="boost_contract/extras.html#boost_contract.extras.disable_contract_compilation__macro_interface_" title="Disable Contract Compilation (Macro Interface)">
        Disable Contract Compilation</a>,  <a class="link" href="boost_contract/extras.html#boost_contract.extras.old_value_requirements__templates_" title="Old Value Requirements (Templates)">
        Old Value Requirements</a> </p>
<p>
</p>
<p>
</p>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2008-2019 Lorenzo Caminiti<p>
        Distributed under the Boost Software License, Version 1.0 (see accompanying
        file LICENSE_1_0.txt or a copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="BOOST_CONTRACT_OLD_PTR.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="reference.html#header.boost.contract_macro_hpp"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="BOOST_CONTRACT_INVARIANT.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
